package cn.edu.zjut.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author:ZhouDan
 * @date: 2020/5/24
 * @version: 1.0
 */
@Entity
@Table(name = "tb_role_info")
@SQLDelete(sql="update tb_role_info set is_delete = 1 where id = ?")
@Where(clause = "is_delete = 0")
public class RoleEntity implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    /**
     *  角色上级Id
     */
    private String parentId;

    /**
     * 角色名称
     */
    private String name;

    /**
     * 角色描述
     */
    private String roleDesc;

    /**
     * 权限标识
     */
    private String permission;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRoleDesc() {
        return roleDesc;
    }

    public void setRoleDesc(String roleDesc) {
        this.roleDesc = roleDesc;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    @JsonIgnoreProperties("roles")
    @ManyToMany(mappedBy = "roles")
    private List<UserEntity> users = new ArrayList<>();

    @Override
    public String toString() {
        return "RoleEntity{" +
                "parentId='" + parentId + '\'' +
                ", name='" + name + '\'' +
                ", roleDesc='" + roleDesc + '\'' +
                ", permission='" + permission + '\'' +
                '}';
    }
}
